package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user_srv/model"
	"user_srv/user_proto"
)

func (s *Server) AddBook(ctx context.Context, in *user_proto.AddBookByNameRequest) (*user_proto.AddBookResponse, error) {
	book := model.Book{
		Name:    in.Name,
		Content: in.Content,
		Types:   in.Types,
		Author:  in.Author,
		Hot:     int(in.Hot),
	}
	err := book.Create()
	if err != nil {
		return nil, status.Errorf(codes.Internal, "漫画添加失败")
	}
	return &user_proto.AddBookResponse{}, nil
}
